<?php

namespace App\Http\Controllers\H5;

use App\Models\Accoutrecord;
use App\Models\Apointccount;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class PointController extends BaseController
{

    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index()
    {


        $wallet = $this->user()->wallet()->firstOrCreate([]);
        return $this->view('h5.point.index', compact('wallet'));
    }

    public function getJson(Request $request)
    {
        $offset = $request->input('offset', 0);
        $count  = $request->input('count', 10);
        $trade_type = intval($request->input('trade_type', 0));

        $items = $this->user()->pointRecords()->where('type', 0)->where('trade_type', $trade_type)
            ->offset($offset)->limit($count)
            ->orderByDesc('id')->get()
        ->map(function ($item){
            $item->created_at = @date('Y-m-d', $item->created_at);
            $item->points = formatAmount($item->points);
            return $item;
        });

        return ajaxReturn(['items'=>$items]);
    }
}
